<template>
    <a-modal
      destroyOnClose
      :title="title"
      :width="900"
      :visible="visible"
      @ok="handleOk"
      @cancel="handleCancel"
      cancelText="关闭">

      <div>
        <a-form-model ref="ruleForm" :model="form" :rules="rules">
          <a-form-model-item label="用户名：" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }" prop="userName">
            <!-- <a-input-search placeholder="点击选择用户" readOnly @search="handleSelect" v-model="form.userName">
              <a-button slot="enterButton" icon="search">选择</a-button>
            </a-input-search> -->
            <j-select-user-by-dep v-model="form.userName" readOnly :multi="false" @back="selectUserOK" :backUser="true"></j-select-user-by-dep>
          </a-form-model-item>
        </a-form-model>
      </div>
      <div style="margin-left:30px">{{message}}</div>
    <select-single-user-modal ref="selectSingleUserModal" @selectFinished="selectUserOK"></select-single-user-modal>
    </a-modal>
</template>

<script>
  import SelectSingleUserModal from "./SelectSingleUserModal";

  export default {
    components: {SelectSingleUserModal},
    name: 'SelectEntrusterModal',
    data() {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 2 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        message:"",
        title:"",
        visible:false,
        form:{
          userName:""
        },
        rules: {
          userName: [{ required: true, message: '请选择用户', trigger: ['change', 'blur'] }],
        },
        userInfo:{},
      }
    },
    created() {

    },
    methods: {
      handleCancel() {
        this.visible = false;
      },
      handleOk() {
        this.$refs.ruleForm.validate(valid => {
          if (valid) {
            this.$emit("selectFinished",this.userInfo);
            this.visible = false;
            this.form.userName = "";
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      selectUserOK: function(data){
        console.log(data[0])
        this.userInfo = data[0];
       // this.$set(this.form,"userName",data[0].realname);
        this.$refs.ruleForm.validate();
      },

      select(record) {
        this.visible = true;
      },
      handleSelect: function(){
        this.$refs.selectSingleUserModal.select();
      },
      hqUserSelectReset(){
        //this.hqUserSelectList = {};
      },
    }
  }
</script>

<style scoped>

</style>